<%--
  Created by IntelliJ IDEA.
  User: mi
  Date: 2019/5/24
  Time: 16:03
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page isELIgnored="false" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" type="text/css" href="common/layui/css/layui.css" media="all">
    <link rel="stylesheet" type="text/css" href="common/bootstrap/css/bootstrap.css" media="all">
    <link rel="stylesheet" type="text/css" href="common/global.css" media="all">
    <link rel="stylesheet" type="text/css" href="css/personal.css" media="all">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/mater.min.css">
    <script src="js/jquery2.js"></script>
    <script src="common/bootstrap/js/bootstrap.js"></script>
</head>
<body>
<div class="container-fluid">
    <table class="table  table-hover table-condensed">
        <thead>
        <tr>
            <th>id</th>
            <th>wrname</th>
            <th>warntype_id</th>
            <th>wdatenumber</th>
            <th>depts</th>
            <th>comparecolumn</th>
            <th>maxday</th>
            <th>is_estatus</th>
            <th>is_cstatus</th>
            <th>user_id</th>
            <th>status</th>
            <th>empId</th>
        </tr>
        </thead>
        <tbody id="tbody" class="table table-striped">

        </tbody>
    </table>
    <button class="btn btn-info" id="referrerBtn" onclick="window.location.href=document.referrer">返回</button>
    <button class="btn btn-success" id="update" class="btn btn-primary btn-lg" data-toggle="modal"
            data-target="#myModal2">UPDATE
    </button>
    <button class="btn btn-danger" id="delete" class="btn btn-link">DELETE</button>
    <button class="btn btn-danger" id="add" class="btn btn-link" data-toggle="modal" data-target="#myModal3">ADD
    </button>
    <button class="btn btn-danger" id="ecq" class="btn btn-link" data-toggle="modal" data-target="#myModal4">ECQ
    </button>

    <%--修改模态框--%>
    <div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">×</span>
                    </button>
                </div>
                <div class="modal-body">
                    <form id="UpdateWarnType">
                        <div class="form-group" hidden>
                            <label>预警主键</label>
                            <input type="text" class="form-control" id="id" name="id">
                        </div>
                        <div class="form-group">
                            <label>预警名称</label>
                            <input type="text" class="form-control" id="wrname" name="wrname">
                        </div>
                        <div class="form-group">
                            <label>预警类型</label>
                            <select id="warntype_id" name="warntypeId">

                            </select>
                        </div>
                        <div class="form-group">
                            <label>预警天数</label>
                            <input type="text" class="form-control" id="wdatenumber" name="wdatenumber">
                        </div>
                        <div class="form-group">
                            <label>应用范围</label>
                            <input type="text" class="form-control" id="depts" name="depts">
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-link" data-dismiss="modal">Close</button>
                    <button type="button" class="btn btn-link" id="updateSave">Save</button>
                </div>
            </div>
        </div>
    </div>

    <%--添加的模态框--%>
    <div class="modal fade" id="myModal3" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">×</span>
                    </button>
                </div>
                <div class="modal-body">
                    <form id="AddFrom">
                        <div class="form-group">
                            <label>wrname</label>
                            <input type="text" class="form-control" name="wrname">
                        </div>
                        <div class="form-group">
                            <label>warntypeId</label>
                            <select class="layui-select-group" id="warntypeId" name="warntypeId">
                                <option>--请选择--</option>
                                <script>
                                    $(function () {
                                        $.ajax({
                                            type: "get",
                                            url: "warnType/queryWarnTypeAll",
                                            dataType: "json",
                                            success: function (msg) {
                                                $.each(msg, function (index, data) {
                                                    var options = "<option value='" + data.id + "' name='ops'>" + data.wtname + "</option>";
                                                    $("#warntypeId").append(options);
                                                    $("#warntype_id").append(options)
                                                })
                                            }
                                        });
                                    });
                                </script>
                            </select>
                        </div>
                        <div class="form-group">
                            <label>wdatenumber</label>
                            <input type="text" class="form-control" name="wdatenumber">
                        </div>
                        <div class="form-group">
                            <label>depts</label>
                            <input type="text" class="form-control" name="depts">
                        </div>
                        <div class="form-group">
                            <label>comparecolumn</label>
                            <input type="text" class="form-control" name="comparecolumn">
                        </div>
                        <div class="form-group">
                            <label>maxday</label>
                            <input type="text" class="form-control" name="maxday">
                        </div>
                        <div class="form-group" hidden>
                            <label>isEstatus</label>
                            <input type="text" class="form-control" value="Y" name="isEstatus">
                        </div>
                        <div class="form-group" hidden>
                            <label>isCstatus</label>
                            <input type="text" class="form-control" value="Y" name="isCstatus">
                        </div>
                        <div class="form-group">
                            <label>userId</label>
                            <select class="layui-select-group" id="userId" name="userId">
                                <option>--请选择--</option>
                                <script>
                                    $(function () {
                                        $.ajax({
                                            type: "get",
                                            url: "user/queryUserAll",
                                            dataType: "json",
                                            success: function (msg) {
                                                $.each(msg, function (index, data) {
                                                    var options = "<option value='" + data.id + "'>" + data.uname + "</option>";
                                                    $("#userId").append(options);
                                                })
                                            }
                                        });
                                    });
                                </script>
                            </select>
                        </div>
                        <div class="form-group" hidden>
                            <label>status</label>
                            <input type="text" class="form-control" value="Y" hidden name="status">
                        </div>
                        <div class="form-group">
                            <label>empId</label>
                            <select class="layui-select-group" id="empId" name="empId">
                                <option>--请选择--</option>
                                <script>
                                    $(function () {
                                        $.ajax({
                                            type: "get",
                                            url: "lt/queryEmpAll",
                                            dataType: "json",
                                            success: function (msg) {
                                                $.each(msg, function (index, data) {
                                                    var options = "<option value='" + data.id + "'>" + data.empname + "</option>";
                                                    $("#empId").append(options);
                                                    $("#emp_id").append(options);
                                                });
                                            }
                                        });
                                    });
                                </script>
                            </select>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-link" data-dismiss="modal">Close</button>
                    <button type="button" class="btn btn-link" id="addSave">Save</button>
                </div>
            </div>
        </div>
    </div>

    <%--执行的模态框--%>
    <div class="modal fade" id="myModal4" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">×</span>
                    </button>
                </div>
                <div class="modal-body">
                    <form id="exqFrom">
                        <div class="form-group">
                            <label>员工主键</label>
                            <input type="text" class="form-control" name="id" id="ids">
                        </div>
                        <div class="form-group">
                            <label>员工编号</label>
                            <input type="text" class="form-control" name="empid" id="empids">
                        </div>
                        <div class="form-group">
                            <label>员工姓名</label>
                            <input type="text" class="form-control" name="empname" id="empname">
                        </div>
                        <div class="form-group">
                            <label>所在部门</label>
                            <input type="text" class="form-control" name="dname" id="dname">
                        </div>
                        <div class="form-group">
                            <label>所在职位</label>
                            <input type="text" class="form-control" name="name" id="name">
                        </div>
                        <div class="form-group">
                            <label>预警方案</label>
                            <input type="text" class="form-control" name="wrname" id="wrnames">
                        </div>
                        <div class="form-group">
                            <label>预警方案</label>
                            <select name="userId" id="user">
                                <option value="">--请选择--</option>
                                <script>
                                    $(function () {
                                        $.ajax({
                                            type: "get",
                                            url: "user/queryUserAll",
                                            dataType: "json",
                                            success: function (msg) {
                                                $.each(msg, function (index, data) {
                                                    var options = "<option value='" + data.id + "'>" + data.uname + "</option>";
                                                    $("#user").append(options);
                                                })
                                            }
                                        });
                                    });
                                </script>
                            </select>
                        </div>
                        <div class="form-group" hidden>
                            <label>状态</label>
                            <input type="text" class="form-control" value="1" name="isStatus">
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-link" data-dismiss="modal">Close</button>
                    <button type="button" class="btn btn-link" id="ok">OK</button>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script>
    /**
     * document.referrer获取前一个url
     */
    if ("http://localhost:8080/maven_project/" == document.referrer ||
        document.referrer == "http://localhost:8080/maven_project/showJob.jsp") {
        var elementById = document.getElementById("referrerBtn");
        elementById.innerText = "刷新";
        elementById.onclick = function () {
            window.location.reload();
        }
    }

    function fun(obj) {
        var firstChild = obj.firstChild;
        var twoChild = firstChild.nextSibling;
        var threeChild = twoChild.nextSibling;
        var foureChild = threeChild.nextSibling;
        var fiveChile = foureChild.nextSibling;
        $("#id").val(firstChild.innerText);
        $("#wrname").val(twoChild.innerText);
        var ops = $("[name='ops']");
        for (var i = 0; i < ops.length; i++) {
            if (ops[i].innerText == threeChild.innerHTML) {
                $(ops[i]).prop("selected", "selected");
            }
        }
        $("#wdatenumber").val(foureChild.innerText);
        $("#depts").val(fiveChile.innerText);

        $.ajax({
            type: "get",
            url: "warnRule/exqWarnruleById",
            data: {
                "id": firstChild.innerText
            },
            dataType: "json",
            success: function (msg) {
                $.each(msg, function (index, data) {
                    $("#ids").val(data.id);
                    $("#empids").val(data.empid);
                    $("#empname").val(data.empname);
                    $("#dname").val(data.dname);
                    $("#name").val(data.name);
                    $("#wrnames").val(data.wrname);
                })
            },
            error: function () {
                window.location.href = "404.jsp";
            }
        });
    }

    $(function () {
        $.ajax({
            type: "get",
            url: "warnRule/queryWarnruleAll",
            dataType: "json",
            success: function (msg) {
                $.each(msg, function (index, data) {
                    var tr = "<tr onclick='fun(this)'>" +
                        "<td>" + data.id + "</td>" +
                        "<td>" + data.wrname + "</td>" +
                        "<td>" + data.wtname + "</td>" +
                        "<td>" + data.wdatenumber + "</td>" +
                        "<td>" + data.depts + "</td>" +
                        "<td>" + data.comparecolumn + "</td>" +
                        "<td>" + data.maxday + "</td>" +
                        "<td>" + data.isEstatus + "</td>" +
                        "<td>" + data.isCstatus + "</td>" +
                        "<td>" + data.userId + "</td>" +
                        "<td>" + data.status + "</td>" +
                        "<td>" + data.empId + "</td>" +
                        "</tr>";
                    $("#tbody").append(tr);
                })
            },
            error: function () {
                window.location.href = "404.jsp";
            }
        });

        $("#updateSave").click(function () {
            $.ajax({
                type: "post",
                url: "warnRule/updateWarnrule",
                data: $("#UpdateWarnType").serialize(),
                dataType: "",
                success: function () {
                    window.location.reload();
                },
                error: function () {
                    window.location.href = "404.jsp";
                }
            });
        });

        $("#addSave").click(function () {
            $.ajax({
                type: "post",
                url: "warnRule/insertWarnrule",
                data: $("#AddFrom").serialize(),
                dataType: "",
                success: function () {
                    window.location.reload();
                },
                error: function () {
                    window.location.href = "404.jsp";
                }
            });
        });
        $("#delete").click(function () {
            alert("确认删除吗?");
            $.ajax({
                type: "get",
                url: "${pageContext.request.contextPath}/warnRule/deleteWarnruleById",
                data: $("#UpdateWarnType").serialize(),
                dataType: "",
                success: function () {
                    window.location.reload();
                },
                error: function () {
                    window.location.href = "404.jsp";
                }
            });
        });

        $("#ok").click(function () {
            $.ajax({
                type: "post",
                url: "warnInfo/insertWarnInfo",
                data: $("#exqFrom").serialize(),
                dataType: "",
                success: function () {
                    window.location.href = "warnRuler.jsp";
                },
                error: function () {
                    window.location.href = "404.jsp";
                }
            });
        });
    });
</script>
</html>
